package com.example.task1.ui.AllService.word;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.WordJobListBean;
import com.example.task1.bean.WordTheDetailBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class WordTheDetailActivity extends AppCompatActivity {

    private TextView tvTitle;
    private TextView tvContent;
    private RecyclerView rvList;
    private Button btnSend;
    private WordJobListAdapter mWordJobListAdapter;
    private LinearLayoutManager mLinearLayoutManager;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_the_detail);
        id = getIntent().getIntExtra("id", 0);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("公司详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        initView();
        initData();
        setAdapter();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }


    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvContent = (TextView) findViewById(R.id.tv_content);
        rvList = (RecyclerView) findViewById(R.id.rv_list);
        btnSend = (Button) findViewById(R.id.btn_send);
    }

    private void setAdapter() {
        mLinearLayoutManager = new LinearLayoutManager(this);
        mWordJobListAdapter = new WordJobListAdapter();
        rvList.setAdapter(mWordJobListAdapter);
        rvList.setLayoutManager(mLinearLayoutManager);
    }


    private void initData() {
        Call<ApiResp> Call = Api.api().get(MyApplication.TOKEN, "/prod-api/api/job/post/list?companyId="+id);
        Api.send(Call, WordJobListBean.class, new CallBack<WordJobListBean>() {
            @Override
            public void success(WordJobListBean data) {
                mWordJobListAdapter.setData(data.getRows());
            }

            @Override
            public void error(String msg) {

            }
        });

        Call<ApiResp> theCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/job/company/"+id);
        Api.send(theCall, WordTheDetailBean.class, new CallBack<WordTheDetailBean>() {
            @Override
            public void success(WordTheDetailBean data) {
                tvContent.setText(data.getData().getIntroductory());
                tvTitle.setText(data.getData().getCompanyName());
            }

            @Override
            public void error(String msg) {

            }
        });
    }
}